//
//  EPMTextView.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/4/4.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMTextView.h"

@interface EPMTextView()
@property (weak,nonatomic) UILabel* label;
@end

@implementation EPMTextView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    UILabel* label = [[UILabel alloc]init];
    _label = label;
    label.textColor = [UIColor lightGrayColor];
    label.text = @"请输入字符";
    [self addSubview:label];
    //约束
    label.translatesAutoresizingMaskIntoConstraints = NO;
    [[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:8] setActive:YES];
    [[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1 constant:5] setActive:YES];
    [[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeWidth multiplier:1 constant:-10] setActive:YES];
    
    //添加监听事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(labelHidenChanged) name:UITextViewTextDidChangeNotification object:nil];
    
}

- (void)labelHidenChanged{
    self.label.hidden = self.hasText;
}


- (void)setPlaceHolder:(NSString *)placeHolder
{
    _placeHolder = placeHolder;
    _label.text = placeHolder;
}

- (void)setFont:(UIFont *)font{
    [super setFont:font];
    self.label.font = font;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

@end
